
<%@page import="com.sopt.contents.FriendsContents"%>
<%@page import="com.sopt.contents.ContentsProc"%><%@page import="org.json.JSONException"%>
<%@page import="org.json.JSONObject"%>
<%@page import="com.sopt.member.FriendsMember"%>
<%@page import="com.sopt.member.MemberProc"%>
<%@page import="com.sopt.comm.util.SoptHashMap"%>
<%@page import="java.util.GregorianCalendar"%>
<%@page import="java.util.Date"%><%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.sopt.comm.util.RequestManager"%>
<%
	
//들어온 번호 둘다 검사 후 존재 하지 않으면 등록 ㄱㄱ


	SoptHashMap hm = RequestManager.getRequest(request);
	System.out.println(hm.toString());
	
	MemberProc mem = new MemberProc();
	ContentsProc contentProc = new ContentsProc();
	FriendsContents friendCont = new FriendsContents();
	
	if(hm.get("NUMBER")!=null){
		if(!mem.isExistMember(hm.get("NUMBER").toString())){
			String senderResult = mem.regMember(hm.get("NUMBER").toString());
		}
		int senderSeq = mem.getMemberSeqByNumber(hm.get("NUMBER").toString());
		if(senderSeq>0)
			friendCont.setMemberseq(senderSeq);
		
	}
	
	if(hm.get("RELATIVE_NUMBER")!=null){
		if(!mem.isExistMember(hm.get("RELATIVE_NUMBER").toString())){
			String senderResult = mem.regMember(hm.get("RELATIVE_NUMBER").toString());
		}
		int rSeq = mem.getMemberSeqByNumber(hm.get("RELATIVE_NUMBER").toString());
		if(rSeq>0)
			friendCont.setTargetmemberseq(rSeq);
	}
	
	
	if(hm.get("CONTENT")!=null)
		friendCont.setContent(hm.get("CONTENT").toString());
	FriendsContents resultContent = contentProc.regContents(friendCont);
	
	if(resultContent.equals(friendCont)){
		JSONObject resultJson = new JSONObject(); 
		resultJson.put("result",new JSONObject(hm));
		out.print(resultJson.toString());
	}else{
		out.print("ERROR");
	}
%>